package public

import (
	"context"
	"errors"

	"server/internal/svc"
	"server/models"
	"server/utils"

	"github.com/zeromicro/go-zero/core/logx"
)

type InitAdminLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewInitAdminLogic(ctx context.Context, svcCtx *svc.ServiceContext) *InitAdminLogic {
	return &InitAdminLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *InitAdminLogic) InitAdmin() (resp string, err error) {
	user := &models.Admin{}
	if utils.GetDataById(1, user) {
		return "", errors.New("超级管理员已存在")
	}
	user.Username = "超级管理员"
	user.RealName = "超级管理员"
	user.Status = 10
	user.Mobile = "18660053536"
	user.Email = "lhyfe1987@163.com"
	user.Password = utils.MD5("haiyan.com")
	user.RoleId = 0
	err = utils.InsertData(user)
	if err != nil {
		return "", err
	}

	return "操作成功", nil
}
